﻿#region Imports
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using LinqDemo.Models;
using LinqDemo.Utilities;
using System.Windows.Forms;
#endregion

namespace LinqDemo.ViewModels
{
    #region Command-ing
    public class MyEventArgs : EventArgs
    {
        public double ProgressChanged;
    }

    public delegate void ChangedEventHandler(object sender, MyEventArgs e);
    #endregion

    public class MainViewModel : BaseViewModel
    {
        #region Declarations
        const Int32 iGap = 5;
        const string sDelim = "~";
        const string sDefaultLink = "All";
        const string sAggregate = "--";
        #endregion

        #region Command declarations
        //public ICommand NavFilterCommand { get; set; }
        #endregion

        #region Constructors
        public MainViewModel()
        {
            InitializeFields();

            NavFilterCommand = new DelegateCommand(OnSelectionChanged);
        }

        public ICommand NavFilterCommand { get; private set; }

        public void OnSelectionChanged(object parameter)
        {
            MessageBox.Show("Test");
            MessageBox.Show((string)parameter);
        }

        // RKD
        //CountryFilterCommand = new Command(FilterResultsOnNavLinks);
        //CommandBinding z = new CommandBinding(this);
        //SelectionChangedCommand = new DelegateCommand((o) => SelectionChanged);
        //}
        //
        //private void SelectionChanged(object command)
        //{
        //    // write logic here
        //}
        //
        //private DelegateCommand _browseCommand;
        //public ICommand SelectionChangedCommand
        //{
        //    get
        //    {
        //        if (_browseCommand == null)
        //            _browseCommand = new DelegateCommand((o) => SelectionChanged(true));
        //        return _browseCommand;
        //    }
        //}
        #endregion

        #region Methods
        private void InitializeFields()
        {
            PopulateData();
            AddFilters();

            IsOptionAllSelected = true;
        }

        private void AddFilters()
        {
            // RKD: do from properties
            Dictionary<string, string> filterConditions = new Dictionary<string, string>();
            filterConditions.Add("CountrySize", "CountrySize");
            FilterConditions = filterConditions;
        }

        private void FilterResultsOnNavLinks(string paramter)
        {
            try
            {
                if (paramter != null)
                {
                    if (paramter == sDefaultLink)
                    { AllPagedCountries = AllCountries; }
                    else if (paramter.Contains(sDelim))
                    {
                        List<string> starters = paramter.Split(sDelim.ToCharArray()).ToList();
                        int iStart = (int)Convert.ToChar(starters[0]); int iEnd = (int)Convert.ToChar(starters[1]);

                        AllPagedCountries = new ObservableCollection<CountryMaster>(
                            AllCountries.Where(cm => GetAsciiValue(cm.CountryName) >= iStart && GetAsciiValue(cm.CountryName) <= iEnd));
                    }
                    else
                    {
                        AllPagedCountries = new ObservableCollection<CountryMaster>(
                            AllCountries.Where(cm => cm.CountryName.StartsWith(paramter)));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private int GetAsciiValue(string s)
        {
            return Convert.ToInt32(s.ToUpper().ToCharArray().First());
        }

        private void PopulateData()
        {
            ObservableCollection<CountryMaster> allCountries
                = new ObservableCollection<CountryMaster>();

            allCountries.Add(new CountryMaster { CountryId = 1, CountryName = "Afghanistan", CountryCode = "AF", GeographyName = "Asia", RegionName = "Asia", CountrySize = 645807, Population = 30419928 });
            allCountries.Add(new CountryMaster { CountryId = 2, CountryName = "Africa", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = 30221532, Population = 1073380925 });
            allCountries.Add(new CountryMaster { CountryId = 3, CountryName = "Albania", CountryCode = "AL", GeographyName = "Europe", RegionName = "Europe", CountrySize = 28748, Population = 2986952 });
            allCountries.Add(new CountryMaster { CountryId = 4, CountryName = "Algeria", CountryCode = "DZ", GeographyName = "", RegionName = "", CountrySize = 2381741, Population = 34586184 });
            allCountries.Add(new CountryMaster { CountryId = 5, CountryName = "American Samoa", CountryCode = "AS", GeographyName = "", RegionName = "", CountrySize = 197, Population = 67242 });
            allCountries.Add(new CountryMaster { CountryId = 6, CountryName = "Andorra", CountryCode = "AD", GeographyName = "Europe", RegionName = "Europe", CountrySize = 464, Population = 84525 });
            allCountries.Add(new CountryMaster { CountryId = 7, CountryName = "Angola", CountryCode = "AO", GeographyName = "", RegionName = "", CountrySize = 1246700, Population = 13068161 });
            allCountries.Add(new CountryMaster { CountryId = 8, CountryName = "Anguilla", CountryCode = "AI", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 96, Population = 15094 });
            allCountries.Add(new CountryMaster { CountryId = 9, CountryName = "Antarctica", CountryCode = "AQ", GeographyName = "", RegionName = "", CountrySize = 13209000, Population = 1169 });
            allCountries.Add(new CountryMaster { CountryId = 10, CountryName = "Antigua & Barbuda", CountryCode = "AG", GeographyName = "", RegionName = "", CountrySize = 442, Population = 87884 });
            allCountries.Add(new CountryMaster { CountryId = 11, CountryName = "Antilles, Netherlands", CountryCode = "AN", GeographyName = "", RegionName = "", CountrySize = 800, Population = 199800 });
            allCountries.Add(new CountryMaster { CountryId = 12, CountryName = "Arabia, Saudi", CountryCode = "SA", GeographyName = "", RegionName = "", CountrySize = 2149690, Population = 26161703 });
            allCountries.Add(new CountryMaster { CountryId = 13, CountryName = "Argentina", CountryCode = "AR", GeographyName = "South America", RegionName = "South America", CountrySize = 2777409, Population = 41769726 });
            allCountries.Add(new CountryMaster { CountryId = 14, CountryName = "Armenia", CountryCode = "AM", GeographyName = "Asia", RegionName = "Asia", CountrySize = 29743, Population = 2967975 });
            allCountries.Add(new CountryMaster { CountryId = 15, CountryName = "Aruba", CountryCode = "AW", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 193, Population = 106113 });
            allCountries.Add(new CountryMaster { CountryId = 16, CountryName = "Asia", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = 39365000, Population = 3922066987 });
            allCountries.Add(new CountryMaster { CountryId = 17, CountryName = "Australia", CountryCode = "AU", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 7682557, Population = 21766711 });
            allCountries.Add(new CountryMaster { CountryId = 18, CountryName = "Austria", CountryCode = "AT", GeographyName = "Europe", RegionName = "European Union", CountrySize = 83858, Population = 8217280 });
            allCountries.Add(new CountryMaster { CountryId = 19, CountryName = "Azerbaijan", CountryCode = "AZ", GeographyName = "Asia", RegionName = "Asia", CountrySize = 86530, Population = 8372373 });
            allCountries.Add(new CountryMaster { CountryId = 20, CountryName = "Bahamas, The", CountryCode = "BS", GeographyName = "", RegionName = "", CountrySize = 13962, Population = 313312 });
            allCountries.Add(new CountryMaster { CountryId = 21, CountryName = "Bahrain", CountryCode = "BH", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 694, Population = 1214705 });
            allCountries.Add(new CountryMaster { CountryId = 22, CountryName = "Bangladesh", CountryCode = "BD", GeographyName = "Asia", RegionName = "Asia", CountrySize = 142615, Population = 158570535 });
            allCountries.Add(new CountryMaster { CountryId = 23, CountryName = "Barbados", CountryCode = "BB", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 431, Population = 286705 });
            allCountries.Add(new CountryMaster { CountryId = 24, CountryName = "Belarus", CountryCode = "BY", GeographyName = "Europe", RegionName = "Europe", CountrySize = 207600, Population = 9577552 });
            allCountries.Add(new CountryMaster { CountryId = 25, CountryName = "Belgium", CountryCode = "BE", GeographyName = "Europe", RegionName = "European Union", CountrySize = 30518, Population = 10431477 });
            allCountries.Add(new CountryMaster { CountryId = 26, CountryName = "Belize", CountryCode = "BZ", GeographyName = "North America", RegionName = "Central America", CountrySize = 22966, Population = 321115 });
            allCountries.Add(new CountryMaster { CountryId = 27, CountryName = "Benin", CountryCode = "BJ", GeographyName = "", RegionName = "", CountrySize = 112622, Population = 9325032 });
            allCountries.Add(new CountryMaster { CountryId = 28, CountryName = "Bermuda", CountryCode = "BM", GeographyName = "North America", RegionName = "Northern America", CountrySize = 53, Population = 68679 });
            allCountries.Add(new CountryMaster { CountryId = 29, CountryName = "Bhutan", CountryCode = "BT", GeographyName = "Asia", RegionName = "Asia", CountrySize = 46650, Population = 708427 });
            allCountries.Add(new CountryMaster { CountryId = 30, CountryName = "Bolivia", CountryCode = "BO", GeographyName = "South America", RegionName = "South America", CountrySize = 1098581, Population = 10118683 });
            allCountries.Add(new CountryMaster { CountryId = 31, CountryName = "Bosnia and Herzegovina", CountryCode = "BA", GeographyName = "", RegionName = "", CountrySize = 51129, Population = 4622163 });
            allCountries.Add(new CountryMaster { CountryId = 32, CountryName = "Botswana", CountryCode = "BW", GeographyName = "", RegionName = "", CountrySize = 581730, Population = 2065398 });
            allCountries.Add(new CountryMaster { CountryId = 33, CountryName = "Bouvet Island", CountryCode = "BV", GeographyName = "", RegionName = "", CountrySize = 49, Population = 0 });
            allCountries.Add(new CountryMaster { CountryId = 34, CountryName = "Brazil", CountryCode = "BR", GeographyName = "South America", RegionName = "South America", CountrySize = 8544418, Population = 194037075 });
            allCountries.Add(new CountryMaster { CountryId = 35, CountryName = "British Indian Ocean T.", CountryCode = "IO", GeographyName = "", RegionName = "", CountrySize = -9999, Population = -9999 });
            allCountries.Add(new CountryMaster { CountryId = 36, CountryName = "British Virgin Islands", CountryCode = "VG", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 151, Population = 25383 });
            allCountries.Add(new CountryMaster { CountryId = 37, CountryName = "Brunei Darussalam", CountryCode = "BN", GeographyName = "Asia", RegionName = "Asia", CountrySize = 5765, Population = 401890 });
            allCountries.Add(new CountryMaster { CountryId = 38, CountryName = "Bulgaria", CountryCode = "BG", GeographyName = "Europe", RegionName = "European Union", CountrySize = 110994, Population = 7093635 });
            allCountries.Add(new CountryMaster { CountryId = 39, CountryName = "Burkina Faso", CountryCode = "BF", GeographyName = "", RegionName = "", CountrySize = 267950, Population = 16751455 });
            allCountries.Add(new CountryMaster { CountryId = 40, CountryName = "Burundi", CountryCode = "BI", GeographyName = "", RegionName = "", CountrySize = 27834, Population = 10216190 });
            allCountries.Add(new CountryMaster { CountryId = 41, CountryName = "Cambodia", CountryCode = "KH", GeographyName = "Asia", RegionName = "Asia", CountrySize = 181035, Population = 14701717 });
            allCountries.Add(new CountryMaster { CountryId = 42, CountryName = "Cameroon", CountryCode = "CM", GeographyName = "", RegionName = "", CountrySize = 475442, Population = 19711291 });
            allCountries.Add(new CountryMaster { CountryId = 43, CountryName = "Canada", CountryCode = "CA", GeographyName = "North America", RegionName = "Northern America", CountrySize = 9976137, Population = 34030586 });
            allCountries.Add(new CountryMaster { CountryId = 44, CountryName = "Cape Verde", CountryCode = "CV", GeographyName = "", RegionName = "", CountrySize = 4033, Population = 516100 });
            allCountries.Add(new CountryMaster { CountryId = 45, CountryName = "Caribbean, the", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = -9999, Population = 40819607 });
            allCountries.Add(new CountryMaster { CountryId = 46, CountryName = "Cayman Islands", CountryCode = "KY", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 259, Population = 51384 });
            allCountries.Add(new CountryMaster { CountryId = 47, CountryName = "Central African Republic", CountryCode = "CF", GeographyName = "", RegionName = "", CountrySize = 622436, Population = 4950027 });
            allCountries.Add(new CountryMaster { CountryId = 48, CountryName = "Central America", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = -9999, Population = 157663596 });
            allCountries.Add(new CountryMaster { CountryId = 49, CountryName = "Chad", CountryCode = "TD", GeographyName = "", RegionName = "", CountrySize = 1284000, Population = 10758945 });
            allCountries.Add(new CountryMaster { CountryId = 50, CountryName = "Chile", CountryCode = "CL", GeographyName = "South America", RegionName = "South America", CountrySize = 755482, Population = 16888760 });
            allCountries.Add(new CountryMaster { CountryId = 51, CountryName = "China", CountryCode = "CN", GeographyName = "Asia", RegionName = "Asia", CountrySize = 9806391, Population = 1336718015 });
            allCountries.Add(new CountryMaster { CountryId = 52, CountryName = "Christmas Island", CountryCode = "CX", GeographyName = "", RegionName = "", CountrySize = 135, Population = 1402 });
            allCountries.Add(new CountryMaster { CountryId = 53, CountryName = "Cocos (Keeling) Islands", CountryCode = "CC", GeographyName = "", RegionName = "", CountrySize = 14, Population = 596 });
            allCountries.Add(new CountryMaster { CountryId = 54, CountryName = "Colombia", CountryCode = "CO", GeographyName = "South America", RegionName = "South America", CountrySize = 1141748, Population = 44725543 });
            allCountries.Add(new CountryMaster { CountryId = 55, CountryName = "Comoros", CountryCode = "KM", GeographyName = "", RegionName = "", CountrySize = 1862, Population = 794683 });
            allCountries.Add(new CountryMaster { CountryId = 56, CountryName = "Congo", CountryCode = "CG", GeographyName = "", RegionName = "", CountrySize = 342000, Population = 4243929 });
            allCountries.Add(new CountryMaster { CountryId = 57, CountryName = "Congo, Dem. Rep. of the", CountryCode = "CD", GeographyName = "", RegionName = "", CountrySize = 2344798, Population = 71712867 });
            allCountries.Add(new CountryMaster { CountryId = 58, CountryName = "Cook Islands", CountryCode = "CK", GeographyName = "", RegionName = "", CountrySize = 237, Population = 11124 });
            allCountries.Add(new CountryMaster { CountryId = 59, CountryName = "Costa Rica", CountryCode = "CR", GeographyName = "North America", RegionName = "Central America", CountrySize = 51090, Population = 4576562 });
            allCountries.Add(new CountryMaster { CountryId = 60, CountryName = "Cote D'Ivoire", CountryCode = "CI", GeographyName = "", RegionName = "", CountrySize = 322461, Population = 21504162 });
            allCountries.Add(new CountryMaster { CountryId = 61, CountryName = "Croatia", CountryCode = "HR", GeographyName = "Europe", RegionName = "Europe", CountrySize = 56542, Population = 4483804 });
            allCountries.Add(new CountryMaster { CountryId = 62, CountryName = "Cuba", CountryCode = "CU", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 114525, Population = 11087330 });
            allCountries.Add(new CountryMaster { CountryId = 63, CountryName = "Cyprus", CountryCode = "CY", GeographyName = "Europe", RegionName = "European Union", CountrySize = 9251, Population = 1120489 });
            allCountries.Add(new CountryMaster { CountryId = 64, CountryName = "Czech Republic", CountryCode = "CZ", GeographyName = "Europe", RegionName = "European Union", CountrySize = 78866, Population = 10190213 });
            allCountries.Add(new CountryMaster { CountryId = 65, CountryName = "Denmark", CountryCode = "DK", GeographyName = "Europe", RegionName = "European Union", CountrySize = 43093, Population = 5529888 });
            allCountries.Add(new CountryMaster { CountryId = 66, CountryName = "Djibouti", CountryCode = "DJ", GeographyName = "", RegionName = "", CountrySize = 23200, Population = 757074 });
            allCountries.Add(new CountryMaster { CountryId = 67, CountryName = "Dominica", CountryCode = "DM", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 751, Population = 72969 });
            allCountries.Add(new CountryMaster { CountryId = 68, CountryName = "Dominican Republic", CountryCode = "DO", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 48734, Population = 9956648 });
            allCountries.Add(new CountryMaster { CountryId = 69, CountryName = "East Timor (Timor-Leste)", CountryCode = "TP", GeographyName = "", RegionName = "", CountrySize = 14604, Population = 1177834 });
            allCountries.Add(new CountryMaster { CountryId = 70, CountryName = "Ecuador", CountryCode = "EC", GeographyName = "South America", RegionName = "South America", CountrySize = 272046, Population = 15007343 });
            allCountries.Add(new CountryMaster { CountryId = 71, CountryName = "Egypt", CountryCode = "EG", GeographyName = "", RegionName = "", CountrySize = 1001450, Population = 82079636 });
            allCountries.Add(new CountryMaster { CountryId = 72, CountryName = "El Salvador", CountryCode = "SV", GeographyName = "North America", RegionName = "Central America", CountrySize = 21041, Population = 6071774 });
            allCountries.Add(new CountryMaster { CountryId = 73, CountryName = "Equatorial Guinea", CountryCode = "GQ", GeographyName = "", RegionName = "", CountrySize = 28051, Population = 668225 });
            allCountries.Add(new CountryMaster { CountryId = 74, CountryName = "Eritrea", CountryCode = "ER", GeographyName = "", RegionName = "", CountrySize = 121100, Population = 5939484 });
            allCountries.Add(new CountryMaster { CountryId = 75, CountryName = "Estonia", CountryCode = "EE", GeographyName = "Europe", RegionName = "European Union", CountrySize = 45226, Population = 1282963 });
            allCountries.Add(new CountryMaster { CountryId = 76, CountryName = "Ethiopia", CountryCode = "ET", GeographyName = "", RegionName = "", CountrySize = 1127127, Population = 90873739 });
            allCountries.Add(new CountryMaster { CountryId = 77, CountryName = "Europe", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = 10180000, Population = 816372817 });
            allCountries.Add(new CountryMaster { CountryId = 78, CountryName = "European Union", CountryCode = "EU", GeographyName = "Europe", RegionName = "Europe", CountrySize = 4324782, Population = 503345807 });
            allCountries.Add(new CountryMaster { CountryId = 79, CountryName = "Falkland Islands (Malvinas)", CountryCode = "FK", GeographyName = "South America", RegionName = "South America", CountrySize = 16076, Population = 3140 });
            allCountries.Add(new CountryMaster { CountryId = 80, CountryName = "Faroe Islands", CountryCode = "FO", GeographyName = "Europe", RegionName = "Europe", CountrySize = 1414, Population = 49057 });
            allCountries.Add(new CountryMaster { CountryId = 81, CountryName = "Fiji", CountryCode = "FJ", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 18274, Population = 883125 });
            allCountries.Add(new CountryMaster { CountryId = 82, CountryName = "Finland", CountryCode = "FI", GeographyName = "Europe", RegionName = "European Union", CountrySize = 338145, Population = 5259250 });
            allCountries.Add(new CountryMaster { CountryId = 83, CountryName = "France", CountryCode = "FR", GeographyName = "Europe", RegionName = "European Union", CountrySize = 547030, Population = 65102719 });
            allCountries.Add(new CountryMaster { CountryId = 84, CountryName = "French Guiana", CountryCode = "GF", GeographyName = "South America", RegionName = "South America", CountrySize = 83534, Population = 235690 });
            allCountries.Add(new CountryMaster { CountryId = 85, CountryName = "French Polynesia", CountryCode = "PF", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 3894, Population = 294935 });
            allCountries.Add(new CountryMaster { CountryId = 86, CountryName = "French Southern Terr.", CountryCode = "TF", GeographyName = "", RegionName = "", CountrySize = 7781, Population = 120 });
            allCountries.Add(new CountryMaster { CountryId = 87, CountryName = "Gabon", CountryCode = "GA", GeographyName = "", RegionName = "", CountrySize = 267667, Population = 1576665 });
            allCountries.Add(new CountryMaster { CountryId = 88, CountryName = "Gambia, the", CountryCode = "GM", GeographyName = "", RegionName = "", CountrySize = 10689, Population = 1797860 });
            allCountries.Add(new CountryMaster { CountryId = 89, CountryName = "Georgia", CountryCode = "GE", GeographyName = "Asia", RegionName = "Asia", CountrySize = 69700, Population = 4585874 });
            allCountries.Add(new CountryMaster { CountryId = 90, CountryName = "Germany", CountryCode = "DE", GeographyName = "Europe", RegionName = "European Union", CountrySize = 357021, Population = 81471834 });
            allCountries.Add(new CountryMaster { CountryId = 91, CountryName = "Ghana", CountryCode = "GH", GeographyName = "", RegionName = "", CountrySize = 238538, Population = 24791073 });
            allCountries.Add(new CountryMaster { CountryId = 92, CountryName = "Gibraltar", CountryCode = "GI", GeographyName = "Europe", RegionName = "Europe", CountrySize = 7, Population = 28956 });
            allCountries.Add(new CountryMaster { CountryId = 93, CountryName = "Greece", CountryCode = "GR", GeographyName = "Europe", RegionName = "European Union", CountrySize = 131957, Population = 10760136 });
            allCountries.Add(new CountryMaster { CountryId = 94, CountryName = "Greenland", CountryCode = "GL", GeographyName = "North America", RegionName = "Northern America", CountrySize = 2175600, Population = 57670 });
            allCountries.Add(new CountryMaster { CountryId = 95, CountryName = "Grenada", CountryCode = "GD", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 345, Population = 108419 });
            allCountries.Add(new CountryMaster { CountryId = 96, CountryName = "Guadeloupe", CountryCode = "GP", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 1780, Population = 405500 });
            allCountries.Add(new CountryMaster { CountryId = 97, CountryName = "Guam", CountryCode = "GU", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 545, Population = 183286 });
            allCountries.Add(new CountryMaster { CountryId = 98, CountryName = "Guatemala", CountryCode = "GT", GeographyName = "North America", RegionName = "Central America", CountrySize = 108894, Population = 13824463 });
            allCountries.Add(new CountryMaster { CountryId = 99, CountryName = "Guernsey and Alderney", CountryCode = "GG", GeographyName = "", RegionName = "", CountrySize = 91, Population = 65068 });
            allCountries.Add(new CountryMaster { CountryId = 100, CountryName = "Guiana, French", CountryCode = "GF", GeographyName = "", RegionName = "", CountrySize = 83534, Population = 235690 });
            allCountries.Add(new CountryMaster { CountryId = 101, CountryName = "Guinea", CountryCode = "GN", GeographyName = "", RegionName = "", CountrySize = 245857, Population = 10601003 });
            allCountries.Add(new CountryMaster { CountryId = 102, CountryName = "Guinea-Bissau", CountryCode = "GW", GeographyName = "", RegionName = "", CountrySize = 36123, Population = 1596677 });
            allCountries.Add(new CountryMaster { CountryId = 103, CountryName = "Guinea, Equatorial", CountryCode = "GP", GeographyName = "", RegionName = "", CountrySize = 28051, Population = 668225 });
            allCountries.Add(new CountryMaster { CountryId = 104, CountryName = "Guyana", CountryCode = "GY", GeographyName = "South America", RegionName = "South America", CountrySize = 215083, Population = 744768 });
            allCountries.Add(new CountryMaster { CountryId = 105, CountryName = "Haiti", CountryCode = "HT", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 27748, Population = 9719932 });
            allCountries.Add(new CountryMaster { CountryId = 106, CountryName = "Heard & McDonald Is.(AU)", CountryCode = "HM", GeographyName = "", RegionName = "", CountrySize = -9999, Population = -9999 });
            allCountries.Add(new CountryMaster { CountryId = 107, CountryName = "Holy See (Vatican)", CountryCode = "VA", GeographyName = "", RegionName = "", CountrySize = -9999, Population = 829 });
            allCountries.Add(new CountryMaster { CountryId = 108, CountryName = "Honduras", CountryCode = "HN", GeographyName = "North America", RegionName = "Central America", CountrySize = 112088, Population = 8143564 });
            allCountries.Add(new CountryMaster { CountryId = 109, CountryName = "Hong Kong, (China)", CountryCode = "HK", GeographyName = "", RegionName = "", CountrySize = 1085, Population = 7122508 });
            allCountries.Add(new CountryMaster { CountryId = 110, CountryName = "Hungary", CountryCode = "HU", GeographyName = "Europe", RegionName = "European Union", CountrySize = 92966, Population = 97976062 });
            allCountries.Add(new CountryMaster { CountryId = 111, CountryName = "Iceland", CountryCode = "IS", GeographyName = "Europe", RegionName = "Europe", CountrySize = 102928, Population = 311058 });
            allCountries.Add(new CountryMaster { CountryId = 112, CountryName = "India", CountryCode = "IN", GeographyName = "Asia", RegionName = "Asia", CountrySize = 3166944, Population = 1189172906 });
            allCountries.Add(new CountryMaster { CountryId = 113, CountryName = "Indonesia", CountryCode = "ID", GeographyName = "Asia", RegionName = "Asia", CountrySize = 1904443, Population = 245613043 });
            allCountries.Add(new CountryMaster { CountryId = 114, CountryName = "Iran, Islamic Republic of", CountryCode = "IR", GeographyName = "", RegionName = "", CountrySize = 1648195, Population = 77891220 });
            allCountries.Add(new CountryMaster { CountryId = 115, CountryName = "Iraq", CountryCode = "IQ", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 434128, Population = 30399572 });
            allCountries.Add(new CountryMaster { CountryId = 116, CountryName = "Ireland", CountryCode = "IE", GeographyName = "Europe", RegionName = "European Union", CountrySize = 70273, Population = 4670976 });
            allCountries.Add(new CountryMaster { CountryId = 117, CountryName = "Israel", CountryCode = "IL", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 20991, Population = 7473052 });
            allCountries.Add(new CountryMaster { CountryId = 118, CountryName = "Italy", CountryCode = "IT", GeographyName = "Europe", RegionName = "European Union", CountrySize = 301323, Population = 61016804 });
            allCountries.Add(new CountryMaster { CountryId = 119, CountryName = "Ivory Coast (Cote d'Ivoire)", CountryCode = "CI", GeographyName = "", RegionName = "", CountrySize = 322461, Population = 21504162 });
            allCountries.Add(new CountryMaster { CountryId = 120, CountryName = "Jamaica", CountryCode = "JM", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 10991, Population = 2868380 });
            allCountries.Add(new CountryMaster { CountryId = 121, CountryName = "Japan", CountryCode = "JP", GeographyName = "Asia", RegionName = "Asia", CountrySize = 377812, Population = 126475664 });
            allCountries.Add(new CountryMaster { CountryId = 122, CountryName = "Jersey", CountryCode = "JE", GeographyName = "Europe", RegionName = "Europe", CountrySize = 116, Population = 94161 });
            allCountries.Add(new CountryMaster { CountryId = 123, CountryName = "Jordan", CountryCode = "JO", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 89342, Population = 6508271 });
            allCountries.Add(new CountryMaster { CountryId = 124, CountryName = "Kazakhstan", CountryCode = "KZ", GeographyName = "Asia", RegionName = "Asia", CountrySize = 2715900, Population = 15522373 });
            allCountries.Add(new CountryMaster { CountryId = 125, CountryName = "Kenya", CountryCode = "KE", GeographyName = "", RegionName = "", CountrySize = 581787, Population = 40070934 });
            allCountries.Add(new CountryMaster { CountryId = 126, CountryName = "Kiribati", CountryCode = "KI", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 832, Population = 100743 });
            allCountries.Add(new CountryMaster { CountryId = 127, CountryName = "Korea Dem. People's Rep.", CountryCode = "KP", GeographyName = "", RegionName = "", CountrySize = 122762, Population = 22757275 });
            allCountries.Add(new CountryMaster { CountryId = 128, CountryName = "Korea, (South) Republic of", CountryCode = "KR", GeographyName = "", RegionName = "", CountrySize = 99268, Population = 48754657 });
            allCountries.Add(new CountryMaster { CountryId = 129, CountryName = "Kosovo", CountryCode = "KV", GeographyName = "Europe", RegionName = "Europe", CountrySize = 10908, Population = 1825632 });
            allCountries.Add(new CountryMaster { CountryId = 130, CountryName = "Kuwait", CountryCode = "KW", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 17818, Population = 2595628 });
            allCountries.Add(new CountryMaster { CountryId = 131, CountryName = "Kyrgyzstan", CountryCode = "KG", GeographyName = "Asia", RegionName = "Asia", CountrySize = 199900, Population = 5587443 });
            allCountries.Add(new CountryMaster { CountryId = 132, CountryName = "Lao People's Democ. Rep.", CountryCode = "LA", GeographyName = "", RegionName = "", CountrySize = 236800, Population = 6477211 });
            allCountries.Add(new CountryMaster { CountryId = 133, CountryName = "Latvia", CountryCode = "LV", GeographyName = "Europe", RegionName = "European Union", CountrySize = 64598, Population = 2204708 });
            allCountries.Add(new CountryMaster { CountryId = 134, CountryName = "Lebanon", CountryCode = "LB", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 10452, Population = 4143101 });
            allCountries.Add(new CountryMaster { CountryId = 135, CountryName = "Lesotho", CountryCode = "LS", GeographyName = "", RegionName = "", CountrySize = 30355, Population = 1924886 });
            allCountries.Add(new CountryMaster { CountryId = 136, CountryName = "Liberia", CountryCode = "LR", GeographyName = "", RegionName = "", CountrySize = 99065, Population = 3786764 });
            allCountries.Add(new CountryMaster { CountryId = 137, CountryName = "Libyan Arab Jamahiriya", CountryCode = "LY", GeographyName = "", RegionName = "", CountrySize = 1777060, Population = 6597960 });
            allCountries.Add(new CountryMaster { CountryId = 138, CountryName = "Liechtenstein", CountryCode = "LI", GeographyName = "Europe", RegionName = "Europe", CountrySize = 160, Population = 35236 });
            allCountries.Add(new CountryMaster { CountryId = 139, CountryName = "Lithuania", CountryCode = "LT", GeographyName = "Europe", RegionName = "European Union", CountrySize = 65300, Population = 3535547 });
            allCountries.Add(new CountryMaster { CountryId = 140, CountryName = "Luxembourg", CountryCode = "LU", GeographyName = "Europe", RegionName = "European Union", CountrySize = 2586, Population = 503302 });
            allCountries.Add(new CountryMaster { CountryId = 141, CountryName = "Macao, (China)", CountryCode = "MO", GeographyName = "", RegionName = "", CountrySize = 25, Population = 573003 });
            allCountries.Add(new CountryMaster { CountryId = 142, CountryName = "Macedonia, TFYR", CountryCode = "MK", GeographyName = "", RegionName = "", CountrySize = 25433, Population = 2077328 });
            allCountries.Add(new CountryMaster { CountryId = 143, CountryName = "Madagascar", CountryCode = "MG", GeographyName = "", RegionName = "", CountrySize = 587041, Population = 21926221 });
            allCountries.Add(new CountryMaster { CountryId = 144, CountryName = "Malawi", CountryCode = "MW", GeographyName = "", RegionName = "", CountrySize = 118480, Population = 15879252 });
            allCountries.Add(new CountryMaster { CountryId = 145, CountryName = "Malaysia", CountryCode = "MY", GeographyName = "Asia", RegionName = "Asia", CountrySize = 329758, Population = 28728607 });
            allCountries.Add(new CountryMaster { CountryId = 146, CountryName = "Maldives", CountryCode = "MV", GeographyName = "Asia", RegionName = "Asia", CountrySize = 298, Population = 394999 });
            allCountries.Add(new CountryMaster { CountryId = 147, CountryName = "Mali", CountryCode = "ML", GeographyName = "", RegionName = "", CountrySize = 1240198, Population = 14159904 });
            allCountries.Add(new CountryMaster { CountryId = 148, CountryName = "Malta", CountryCode = "MT", GeographyName = "Europe", RegionName = "European Union", CountrySize = 315, Population = 408333 });
            allCountries.Add(new CountryMaster { CountryId = 149, CountryName = "Man, Isle of", CountryCode = "IM", GeographyName = "", RegionName = "", CountrySize = 572, Population = 84655 });
            allCountries.Add(new CountryMaster { CountryId = 150, CountryName = "Marshall Islands", CountryCode = "MH", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 181, Population = 67182 });
            allCountries.Add(new CountryMaster { CountryId = 151, CountryName = "Martinique (FR)", CountryCode = "MQ", GeographyName = "", RegionName = "", CountrySize = 1128, Population = 397166 });
            allCountries.Add(new CountryMaster { CountryId = 152, CountryName = "Mauritania", CountryCode = "MR", GeographyName = "", RegionName = "", CountrySize = 1035000, Population = 3281634 });
            allCountries.Add(new CountryMaster { CountryId = 153, CountryName = "Mauritius", CountryCode = "MU", GeographyName = "", RegionName = "", CountrySize = 2040, Population = 1303717 });
            allCountries.Add(new CountryMaster { CountryId = 154, CountryName = "Mayotte (FR)", CountryCode = "YT", GeographyName = "", RegionName = "", CountrySize = 373, Population = 209530 });
            allCountries.Add(new CountryMaster { CountryId = 155, CountryName = "Mexico", CountryCode = "MX", GeographyName = "North America", RegionName = "Central America", CountrySize = 1967138, Population = 115017631 });
            allCountries.Add(new CountryMaster { CountryId = 156, CountryName = "Micronesia, Fed. States of", CountryCode = "FM", GeographyName = "", RegionName = "", CountrySize = 721, Population = 106836 });
            allCountries.Add(new CountryMaster { CountryId = 157, CountryName = "Middle East", CountryCode = "'--", GeographyName = "", RegionName = "", CountrySize = 5214000, Population = 223608203 });
            allCountries.Add(new CountryMaster { CountryId = 158, CountryName = "Moldova, Republic of", CountryCode = "MD", GeographyName = "", RegionName = "", CountrySize = 33843, Population = 4314377 });
            allCountries.Add(new CountryMaster { CountryId = 159, CountryName = "Monaco", CountryCode = "MC", GeographyName = "Europe", RegionName = "Europe", CountrySize = 2, Population = 30539 });
            allCountries.Add(new CountryMaster { CountryId = 160, CountryName = "Mongolia", CountryCode = "MN", GeographyName = "Asia", RegionName = "Asia", CountrySize = 1564160, Population = 3133318 });
            allCountries.Add(new CountryMaster { CountryId = 161, CountryName = "Montenegro", CountryCode = "CS", GeographyName = "Europe", RegionName = "Europe", CountrySize = 14026, Population = 661807 });
            allCountries.Add(new CountryMaster { CountryId = 162, CountryName = "Montserrat", CountryCode = "MS", GeographyName = "", RegionName = "", CountrySize = 102, Population = 5140 });
            allCountries.Add(new CountryMaster { CountryId = 163, CountryName = "Morocco", CountryCode = "MA", GeographyName = "", RegionName = "", CountrySize = 6600000, Population = 31968361 });
            allCountries.Add(new CountryMaster { CountryId = 164, CountryName = "Mozambique", CountryCode = "MZ", GeographyName = "", RegionName = "", CountrySize = 799380, Population = 22948858 });
            allCountries.Add(new CountryMaster { CountryId = 165, CountryName = "Myanmar (ex-Burma)", CountryCode = "MM", GeographyName = "Asia", RegionName = "Asia", CountrySize = 676577, Population = 53999804 });
            allCountries.Add(new CountryMaster { CountryId = 166, CountryName = "Namibia", CountryCode = "NA", GeographyName = "", RegionName = "", CountrySize = 825112, Population = 2147585 });
            allCountries.Add(new CountryMaster { CountryId = 167, CountryName = "Nauru", CountryCode = "NR", GeographyName = "", RegionName = "", CountrySize = 21, Population = 9322 });
            allCountries.Add(new CountryMaster { CountryId = 168, CountryName = "Nepal", CountryCode = "NP", GeographyName = "Asia", RegionName = "Asia", CountrySize = 147181, Population = 29391883 });
            allCountries.Add(new CountryMaster { CountryId = 169, CountryName = "Netherlands", CountryCode = "NL", GeographyName = "Europe", RegionName = "European Union", CountrySize = 41526, Population = 16847007 });
            allCountries.Add(new CountryMaster { CountryId = 170, CountryName = "Netherlands Antilles", CountryCode = "AN", GeographyName = "", RegionName = "", CountrySize = 800, Population = -9999 });
            allCountries.Add(new CountryMaster { CountryId = 171, CountryName = "New Caledonia", CountryCode = "NC", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 18736, Population = 256275 });
            allCountries.Add(new CountryMaster { CountryId = 172, CountryName = "New Zealand", CountryCode = "NZ", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 270534, Population = 4290347 });
            allCountries.Add(new CountryMaster { CountryId = 173, CountryName = "Nicaragua", CountryCode = "NI", GeographyName = "North America", RegionName = "Central America", CountrySize = 129454, Population = 5666301 });
            allCountries.Add(new CountryMaster { CountryId = 174, CountryName = "Niger", CountryCode = "NE", GeographyName = "", RegionName = "", CountrySize = 1186408, Population = 16468886 });
            allCountries.Add(new CountryMaster { CountryId = 175, CountryName = "Nigeria", CountryCode = "NG", GeographyName = "", RegionName = "", CountrySize = 923768, Population = 170123740 });
            allCountries.Add(new CountryMaster { CountryId = 176, CountryName = "Niue", CountryCode = "NU", GeographyName = "", RegionName = "", CountrySize = 259, Population = 1311 });
            allCountries.Add(new CountryMaster { CountryId = 177, CountryName = "Norfolk Island", CountryCode = "NF", GeographyName = "", RegionName = "", CountrySize = 35, Population = 2169 });
            allCountries.Add(new CountryMaster { CountryId = 178, CountryName = "North America", CountryCode = "'--", GeographyName = "", RegionName = "", CountrySize = 24256000, Population = 348280154 });
            allCountries.Add(new CountryMaster { CountryId = 179, CountryName = "Northern Mariana Islands", CountryCode = "MP", GeographyName = "", RegionName = "", CountrySize = 477, Population = 46050 });
            allCountries.Add(new CountryMaster { CountryId = 180, CountryName = "Norway", CountryCode = "NO", GeographyName = "Europe", RegionName = "Europe", CountrySize = 323759, Population = 4691849 });
            allCountries.Add(new CountryMaster { CountryId = 181, CountryName = "Oceania", CountryCode = "'--", GeographyName = "", RegionName = "", CountrySize = 7620480, Population = 35815913 });
            allCountries.Add(new CountryMaster { CountryId = 182, CountryName = "Oman", CountryCode = "OM", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 309500, Population = 3027959 });
            allCountries.Add(new CountryMaster { CountryId = 183, CountryName = "Pakistan", CountryCode = "PK", GeographyName = "Asia", RegionName = "Asia", CountrySize = 880254, Population = 187342721 });
            allCountries.Add(new CountryMaster { CountryId = 184, CountryName = "Palau", CountryCode = "PW", GeographyName = "", RegionName = "", CountrySize = 491, Population = 20956 });
            allCountries.Add(new CountryMaster { CountryId = 185, CountryName = "Palestinian Territory", CountryCode = "PS", GeographyName = "", RegionName = "", CountrySize = 6242, Population = 2568555 });
            allCountries.Add(new CountryMaster { CountryId = 186, CountryName = "Panama", CountryCode = "PA", GeographyName = "North America", RegionName = "Central America", CountrySize = 77082, Population = 3460462 });
            allCountries.Add(new CountryMaster { CountryId = 187, CountryName = "Papua New Guinea", CountryCode = "PG", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 462840, Population = 6187591 });
            allCountries.Add(new CountryMaster { CountryId = 188, CountryName = "Paraguay", CountryCode = "PY", GeographyName = "South America", RegionName = "South America", CountrySize = 406752, Population = 6459058 });
            allCountries.Add(new CountryMaster { CountryId = 189, CountryName = "Peru", CountryCode = "PE", GeographyName = "South America", RegionName = "South America", CountrySize = 1285216, Population = 29248943 });
            allCountries.Add(new CountryMaster { CountryId = 190, CountryName = "Philippines", CountryCode = "PH", GeographyName = "", RegionName = "", CountrySize = 300000, Population = 101833938 });
            allCountries.Add(new CountryMaster { CountryId = 191, CountryName = "Pitcairn Island", CountryCode = "PN", GeographyName = "", RegionName = "", CountrySize = -9999, Population = 48 });
            allCountries.Add(new CountryMaster { CountryId = 192, CountryName = "Poland", CountryCode = "PL", GeographyName = "Europe", RegionName = "European Union", CountrySize = 312685, Population = 38441588 });
            allCountries.Add(new CountryMaster { CountryId = 193, CountryName = "Portugal", CountryCode = "PT", GeographyName = "Europe", RegionName = "European Union", CountrySize = 92391, Population = 10760305 });
            allCountries.Add(new CountryMaster { CountryId = 194, CountryName = "Puerto Rico", CountryCode = "PR", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 9104, Population = 3989133 });
            allCountries.Add(new CountryMaster { CountryId = 195, CountryName = "Qatar", CountryCode = "QA", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 11521, Population = 848016 });
            allCountries.Add(new CountryMaster { CountryId = 196, CountryName = "Reunion (FR)", CountryCode = "RE", GeographyName = "", RegionName = "", CountrySize = 2547, Population = 834261 });
            allCountries.Add(new CountryMaster { CountryId = 197, CountryName = "Romania", CountryCode = "RO", GeographyName = "Europe", RegionName = "European Union", CountrySize = 238391, Population = 21904551 });
            allCountries.Add(new CountryMaster { CountryId = 198, CountryName = "Russia (Russian Fed.)", CountryCode = "RU", GeographyName = "", RegionName = "", CountrySize = 16894741, Population = 138739892 });
            allCountries.Add(new CountryMaster { CountryId = 199, CountryName = "Rwanda", CountryCode = "RW", GeographyName = "", RegionName = "", CountrySize = 26338, Population = 11370425 });
            allCountries.Add(new CountryMaster { CountryId = 200, CountryName = "Sahara, Western", CountryCode = "EH", GeographyName = "", RegionName = "", CountrySize = 266000, Population = 491519 });
            allCountries.Add(new CountryMaster { CountryId = 201, CountryName = "Saint Barthelemy (FR)", CountryCode = "BL", GeographyName = "", RegionName = "", CountrySize = 21, Population = 7367 });
            allCountries.Add(new CountryMaster { CountryId = 202, CountryName = "Saint Helena (UK)", CountryCode = "SH", GeographyName = "", RegionName = "", CountrySize = 410, Population = 7700 });
            allCountries.Add(new CountryMaster { CountryId = 203, CountryName = "Saint Kitts and Nevis", CountryCode = "KN", GeographyName = "", RegionName = "", CountrySize = 267, Population = 50314 });
            allCountries.Add(new CountryMaster { CountryId = 204, CountryName = "Saint Lucia", CountryCode = "LC", GeographyName = "North America", RegionName = "The Caribbean", CountrySize = 616, Population = 161557 });
            allCountries.Add(new CountryMaster { CountryId = 205, CountryName = "Saint Martin (FR)", CountryCode = "MF", GeographyName = "", RegionName = "", CountrySize = 37, Population = 30615 });
            allCountries.Add(new CountryMaster { CountryId = 206, CountryName = "S Pierre & Miquelon(FR)", CountryCode = "PM", GeographyName = "", RegionName = "", CountrySize = 242, Population = 5943 });
            allCountries.Add(new CountryMaster { CountryId = 207, CountryName = "S Vincent & Grenadines", CountryCode = "VC", GeographyName = "", RegionName = "", CountrySize = 392, Population = 103869 });
            allCountries.Add(new CountryMaster { CountryId = 208, CountryName = "Samoa", CountryCode = "WS", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 2785, Population = 193161 });
            allCountries.Add(new CountryMaster { CountryId = 209, CountryName = "San Marino", CountryCode = "SM", GeographyName = "Europe", RegionName = "Europe", CountrySize = 61, Population = 31817 });
            allCountries.Add(new CountryMaster { CountryId = 210, CountryName = "Sao Tome and Principe", CountryCode = "ST", GeographyName = "", RegionName = "", CountrySize = 1001, Population = 179506 });
            allCountries.Add(new CountryMaster { CountryId = 211, CountryName = "Saudi Arabia", CountryCode = "SA", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 2149690, Population = 26131703 });
            allCountries.Add(new CountryMaster { CountryId = 212, CountryName = "Senegal", CountryCode = "SN", GeographyName = "", RegionName = "", CountrySize = 196722, Population = 12643799 });
            allCountries.Add(new CountryMaster { CountryId = 213, CountryName = "Serbia", CountryCode = "RS", GeographyName = "Europe", RegionName = "Europe", CountrySize = 77474, Population = 7310555 });
            allCountries.Add(new CountryMaster { CountryId = 214, CountryName = "Seychelles", CountryCode = "SC", GeographyName = "", RegionName = "", CountrySize = 455, Population = 89188 });
            allCountries.Add(new CountryMaster { CountryId = 215, CountryName = "Sierra Leone", CountryCode = "SL", GeographyName = "", RegionName = "", CountrySize = 71740, Population = 5363669 });
            allCountries.Add(new CountryMaster { CountryId = 216, CountryName = "Singapore", CountryCode = "SG", GeographyName = "Asia", RegionName = "Asia", CountrySize = 683, Population = 4740737 });
            allCountries.Add(new CountryMaster { CountryId = 217, CountryName = "Slovakia", CountryCode = "SK", GeographyName = "Europe", RegionName = "European Union", CountrySize = 49034, Population = 5477038 });
            allCountries.Add(new CountryMaster { CountryId = 218, CountryName = "Slovenia", CountryCode = "SI", GeographyName = "Europe", RegionName = "European Union", CountrySize = 20273, Population = 2000092 });
            allCountries.Add(new CountryMaster { CountryId = 219, CountryName = "Solomon Islands", CountryCode = "SB", GeographyName = "", RegionName = "", CountrySize = 28400, Population = 571890 });
            allCountries.Add(new CountryMaster { CountryId = 220, CountryName = "Somalia", CountryCode = "SO", GeographyName = "", RegionName = "", CountrySize = 637657, Population = 9925640 });
            allCountries.Add(new CountryMaster { CountryId = 221, CountryName = "South Africa", CountryCode = "ZA", GeographyName = "", RegionName = "", CountrySize = 1219090, Population = 49004031 });
            allCountries.Add(new CountryMaster { CountryId = 222, CountryName = "South America", CountryCode = "--", GeographyName = "", RegionName = "", CountrySize = 17819000, Population = 394511639 });
            allCountries.Add(new CountryMaster { CountryId = 223, CountryName = "S.George & S.Sandwich", CountryCode = "GS", GeographyName = "", RegionName = "", CountrySize = 3903, Population = -9999 });
            allCountries.Add(new CountryMaster { CountryId = 224, CountryName = "South Sudan", CountryCode = "SS", GeographyName = "", RegionName = "", CountrySize = 619745, Population = 8260490 });
            allCountries.Add(new CountryMaster { CountryId = 225, CountryName = "Spain", CountryCode = "ES", GeographyName = "Europe", RegionName = "European Union", CountrySize = 504842, Population = 46754784 });
            allCountries.Add(new CountryMaster { CountryId = 226, CountryName = "Sri Lanka (ex-Ceilan)", CountryCode = "LK", GeographyName = "Asia", RegionName = "Asia", CountrySize = 65610, Population = 21283913 });
            allCountries.Add(new CountryMaster { CountryId = 227, CountryName = "Sudan", CountryCode = "SD", GeographyName = "", RegionName = "", CountrySize = 2505810, Population = 45047502 });
            allCountries.Add(new CountryMaster { CountryId = 228, CountryName = "Suriname", CountryCode = "SR", GeographyName = "South America", RegionName = "South America", CountrySize = 163820, Population = 491989 });
            allCountries.Add(new CountryMaster { CountryId = 229, CountryName = "Svalbard & Jan Mayen Is.", CountryCode = "SJ", GeographyName = "", RegionName = "", CountrySize = 61606, Population = 2481 });
            allCountries.Add(new CountryMaster { CountryId = 230, CountryName = "Swaziland", CountryCode = "SZ", GeographyName = "", RegionName = "", CountrySize = 17363, Population = 1370424 });
            allCountries.Add(new CountryMaster { CountryId = 231, CountryName = "Sweden", CountryCode = "SE", GeographyName = "Europe", RegionName = "European Union", CountrySize = 449965, Population = 9088728 });
            allCountries.Add(new CountryMaster { CountryId = 232, CountryName = "Switzerland", CountryCode = "CH", GeographyName = "Europe", RegionName = "Europe", CountrySize = 41285, Population = 7639961 });
            allCountries.Add(new CountryMaster { CountryId = 233, CountryName = "Syrian Arab Republic", CountryCode = "SY", GeographyName = "", RegionName = "", CountrySize = 185180, Population = 22530746 });
            allCountries.Add(new CountryMaster { CountryId = 234, CountryName = "Taiwan", CountryCode = "TW", GeographyName = "Asia", RegionName = "Asia", CountrySize = 36175, Population = 23071779 });
            allCountries.Add(new CountryMaster { CountryId = 235, CountryName = "Tajikistan", CountryCode = "TJ", GeographyName = "Asia", RegionName = "Asia", CountrySize = 143100, Population = 7627200 });
            allCountries.Add(new CountryMaster { CountryId = 236, CountryName = "Tanzania, United Rep. of", CountryCode = "TZ", GeographyName = "", RegionName = "", CountrySize = 945088, Population = 42746620 });
            allCountries.Add(new CountryMaster { CountryId = 237, CountryName = "Thailand", CountryCode = "TH", GeographyName = "Asia", RegionName = "Asia", CountrySize = 513115, Population = 66720153 });
            allCountries.Add(new CountryMaster { CountryId = 238, CountryName = "Timor-Leste (East Timor)", CountryCode = "TL", GeographyName = "", RegionName = "", CountrySize = 14604, Population = 1177834 });
            allCountries.Add(new CountryMaster { CountryId = 239, CountryName = "Togo", CountryCode = "TG", GeographyName = "", RegionName = "", CountrySize = 56785, Population = 6771993 });
            allCountries.Add(new CountryMaster { CountryId = 240, CountryName = "Tokelau", CountryCode = "TK", GeographyName = "", RegionName = "", CountrySize = 10, Population = 1384 });
            allCountries.Add(new CountryMaster { CountryId = 241, CountryName = "Tonga", CountryCode = "TO", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 651, Population = 105916 });
            allCountries.Add(new CountryMaster { CountryId = 242, CountryName = "Trinidad & Tobago", CountryCode = "TT", GeographyName = "", RegionName = "", CountrySize = 5128, Population = 1222505 });
            allCountries.Add(new CountryMaster { CountryId = 243, CountryName = "Tunisia", CountryCode = "TN", GeographyName = "", RegionName = "", CountrySize = 163610, Population = 10629186 });
            allCountries.Add(new CountryMaster { CountryId = 244, CountryName = "Turkey", CountryCode = "TR", GeographyName = "Europe", RegionName = "Europe", CountrySize = 773473, Population = 78785548 });
            allCountries.Add(new CountryMaster { CountryId = 245, CountryName = "Turkmenistan", CountryCode = "TM", GeographyName = "Asia", RegionName = "Asia", CountrySize = 488100, Population = 4997503 });
            allCountries.Add(new CountryMaster { CountryId = 246, CountryName = "Turks and Caicos Is.", CountryCode = "TC", GeographyName = "", RegionName = "", CountrySize = 497, Population = 44819 });
            allCountries.Add(new CountryMaster { CountryId = 247, CountryName = "Tuvalu", CountryCode = "TV", GeographyName = "", RegionName = "", CountrySize = 26, Population = 10544 });
            allCountries.Add(new CountryMaster { CountryId = 248, CountryName = "Uganda", CountryCode = "UG", GeographyName = "", RegionName = "", CountrySize = 242554, Population = 34612250 });
            allCountries.Add(new CountryMaster { CountryId = 249, CountryName = "Ukraine", CountryCode = "UA", GeographyName = "Europe", RegionName = "Europe", CountrySize = 603628, Population = 45134707 });
            allCountries.Add(new CountryMaster { CountryId = 250, CountryName = "United Arab Emirates", CountryCode = "AE", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 77700, Population = 8264070 });
            allCountries.Add(new CountryMaster { CountryId = 251, CountryName = "United Kingdom", CountryCode = "UK", GeographyName = "Europe", RegionName = "European Union", CountrySize = 244140, Population = 62698362 });
            allCountries.Add(new CountryMaster { CountryId = 252, CountryName = "United States", CountryCode = "US", GeographyName = "North America", RegionName = "Northern America", CountrySize = 9629047, Population = 313232044 });
            allCountries.Add(new CountryMaster { CountryId = 253, CountryName = "US Minor Outlying Isl.", CountryCode = "UM", GeographyName = "", RegionName = "", CountrySize = -9999, Population = -9999 });
            allCountries.Add(new CountryMaster { CountryId = 254, CountryName = "Uruguay", CountryCode = "UY", GeographyName = "South America", RegionName = "South America", CountrySize = 175016, Population = 3308535 });
            allCountries.Add(new CountryMaster { CountryId = 255, CountryName = "Uzbekistan", CountryCode = "UZ", GeographyName = "Asia", RegionName = "Asia", CountrySize = 447400, Population = 28128600 });
            allCountries.Add(new CountryMaster { CountryId = 256, CountryName = "Vanuatu", CountryCode = "VU", GeographyName = "Oceania", RegionName = "Oceania", CountrySize = 12190, Population = 224564 });
            allCountries.Add(new CountryMaster { CountryId = 257, CountryName = "Vatican (Holy See)", CountryCode = "VA", GeographyName = "", RegionName = "", CountrySize = 1, Population = 832 });
            allCountries.Add(new CountryMaster { CountryId = 258, CountryName = "Venezuela", CountryCode = "VE", GeographyName = "South America", RegionName = "South America", CountrySize = 916445, Population = 27635743 });
            allCountries.Add(new CountryMaster { CountryId = 259, CountryName = "Viet Nam", CountryCode = "VN", GeographyName = "", RegionName = "", CountrySize = 332378, Population = 90549390 });
            allCountries.Add(new CountryMaster { CountryId = 260, CountryName = "Virgin Islands, British", CountryCode = "VG", GeographyName = "", RegionName = "", CountrySize = 151, Population = 25383 });
            allCountries.Add(new CountryMaster { CountryId = 261, CountryName = "Virgin Islands, U.S.", CountryCode = "VI", GeographyName = "", RegionName = "", CountrySize = 352, Population = 109666 });
            allCountries.Add(new CountryMaster { CountryId = 262, CountryName = "Wallis and Futuna", CountryCode = "WF", GeographyName = "", RegionName = "", CountrySize = 274, Population = 15398 });
            allCountries.Add(new CountryMaster { CountryId = 263, CountryName = "Western Sahara", CountryCode = "EH", GeographyName = "", RegionName = "", CountrySize = 266000, Population = 491519 });
            allCountries.Add(new CountryMaster { CountryId = 264, CountryName = "Yemen", CountryCode = "YE", GeographyName = "Asia", RegionName = "Middle East", CountrySize = 528076, Population = 24771809 });
            allCountries.Add(new CountryMaster { CountryId = 265, CountryName = "Zambia", CountryCode = "ZM", GeographyName = "", RegionName = "", CountrySize = 752614, Population = 13881336 });

            AllCountries = allCountries;
        }

        private void RefreshNavigationLinks()
        {
            try
            {
                if (Utilities.Utilities.IsLinqIterable<CountryMaster>(AllCountries))
                {
                    ObservableCollection<NavigationLink> allNavigationLinks = new ObservableCollection<NavigationLink>();
                    ObservableCollection<NavigationLink> allRangeNavigationLinks = new ObservableCollection<NavigationLink>();

                    allNavigationLinks = new ObservableCollection<NavigationLink>(AllCountries
                        .Select(cm => cm.CountryName.ToUpper().ToCharArray().First().ToString()).Distinct()
                        .Select(nav => new NavigationLink { NavText = nav }));

                    foreach (Int32 quot in AllCountries
                        .Select(cm => GetAsciiValue(cm.CountryName)).Select(asc => asc / iGap).Distinct())
                    {
                        ObservableCollection<Int32> sub = new ObservableCollection<Int32>(
                            AllCountries.Where(cm => GetAsciiValue(cm.CountryName) / iGap == quot)
                            .Select(cm => GetAsciiValue(cm.CountryName)).Distinct());

                        string min = ((char)sub.Min()).ToString();
                        string max = ((char)sub.Max()).ToString();

                        allRangeNavigationLinks.Add(new NavigationLink { NavText = (min == max) ? min : min + sDelim + max });
                    }

                    AllNavigationLinks = allNavigationLinks;
                    AllRangeNavigationLinks = allRangeNavigationLinks;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void AddDefaultLink(ObservableCollection<NavigationLink> navLinks)
        {
            if (Utilities.Utilities.IsLinqIterable<NavigationLink>(navLinks))
            {
                if (navLinks.Where(nav => nav.NavText == sDefaultLink).Count() == 0)
                {
                    navLinks.Add(new NavigationLink { NavText = sDefaultLink });
                    navLinks = new ObservableCollection<NavigationLink>(
                        navLinks.OrderBy(nav => nav.NavText == sDefaultLink ? 0 : 1).ThenBy(nav => nav.NavText));
                }
            }
        }

        private void FilterResultsOnCriteria()
        {
            switch (FilterCount)
            {
                case 0:
                    switch (IsTopChecked)
                    {
                        case true:
                            AllFilteredCountries = new ObservableCollection<CountryFiltered>(allCountries.Where(cm => cm.CountrySize > 10000).OrderBy(cm => cm.CountrySize).Select(cm => new CountryFiltered { CountryId = cm.CountryId, CountryName = cm.CountryName, CountryCode = cm.CountryCode, FilteredValue = cm.CountrySize }));
                            break;
                        case false:
                            AllFilteredCountries = new ObservableCollection<CountryFiltered>(allCountries.Where(cm => cm.CountrySize > 10000).OrderByDescending(cm => cm.CountrySize).Select(cm => new CountryFiltered { CountryId = cm.CountryId, CountryName = cm.CountryName, CountryCode = cm.CountryCode, FilteredValue = cm.CountrySize }));
                            break;
                    }
                    break;
                default:
                    switch (IsTopChecked)
                    {
                        case true:
                            AllFilteredCountries = new ObservableCollection<CountryFiltered>(allCountries.Where(cm => cm.CountrySize > 10000).OrderBy(cm => cm.CountrySize).Take(FilterCount).Select(cm => new CountryFiltered { CountryId = cm.CountryId, CountryName = cm.CountryName, CountryCode = cm.CountryCode, FilteredValue = cm.CountrySize }).OrderBy(cf => cf.FilteredValue));
                            break;
                        case false:
                            AllFilteredCountries = new ObservableCollection<CountryFiltered>(allCountries.Where(cm => cm.CountrySize > 10000).OrderByDescending(cm => cm.CountrySize).Take(FilterCount).Select(cm => new CountryFiltered { CountryId = cm.CountryId, CountryName = cm.CountryName, CountryCode = cm.CountryCode, FilteredValue = cm.CountrySize }).OrderByDescending(cf => cf.FilteredValue));
                            break;
                    }
                    break;
            }
        }
        #endregion

        #region Properties
        private ObservableCollection<NavigationLink> allNavigationLinks = new ObservableCollection<NavigationLink>();
        public ObservableCollection<NavigationLink> AllNavigationLinks
        {
            get { return allNavigationLinks; }
            set
            {
                AddDefaultLink(value); allNavigationLinks = value;
                base.RaisePropertyChanged("AllNavigationLinks");
            }
        }

        private ObservableCollection<NavigationLink> allRangeNavigationLinks = new ObservableCollection<NavigationLink>();
        public ObservableCollection<NavigationLink> AllRangeNavigationLinks
        {
            get { return allRangeNavigationLinks; }
            set
            {
                AddDefaultLink(value); allRangeNavigationLinks = value;
                base.RaisePropertyChanged("AllRangeNavigationLinks");
            }
        }

        private ObservableCollection<CountryMaster> allCountries = new ObservableCollection<CountryMaster>();
        public ObservableCollection<CountryMaster> AllCountries
        {
            get { return allCountries; }
            set
            {
                allCountries = (allCountries != null) ? new ObservableCollection<CountryMaster>(value.Where(cm => cm.CountryCode != sAggregate)) : value;
                base.RaisePropertyChanged("AllCountries");

                AllPagedCountries = allCountries;
                RefreshNavigationLinks();

                MinFilterCount = 0;
                MaxFilterCount = allCountries.Count();
                FilterCount = MinFilterCount;
            }
        }

        private ObservableCollection<CountryMaster> allPagedCountries;
        public ObservableCollection<CountryMaster> AllPagedCountries
        {
            get { return allPagedCountries; }
            set { allPagedCountries = value; base.RaisePropertyChanged("AllPagedCountries"); }
        }

        private ObservableCollection<CountryFiltered> allFilteredCountries;
        public ObservableCollection<CountryFiltered> AllFilteredCountries
        {
            get { return allFilteredCountries; }
            set { allFilteredCountries = value; base.RaisePropertyChanged("AllFilteredCountries"); }
        }

        private string filteredHeader;
        public string FilteredHeader
        {
            get { return filteredHeader; }
            set { filteredHeader = value; base.RaisePropertyChanged("FilteredHeader"); }
        }

        private object filteredValue;
        public object FilteredValue
        {
            get { return filteredValue; }
            set { filteredValue = value; base.RaisePropertyChanged("FilteredValue"); }
        }

        private bool isOptionAllSelected;
        public bool IsOptionAllSelected
        {
            get { return isOptionAllSelected; }
            set { isOptionAllSelected = value; base.RaisePropertyChanged("IsOptionAllSelected"); }
        }

        private int filterCount;
        public int FilterCount
        {
            get { return filterCount; }
            set
            {
                filterCount = value; base.RaisePropertyChanged("FilterCount");
                FilterResultsOnCriteria();
            }
        }

        private int minFilterCount;
        public int MinFilterCount
        {
            get { return minFilterCount; }
            set { minFilterCount = value; base.RaisePropertyChanged("MinFilterCount"); }
        }

        private int maxFilterCount;
        public int MaxFilterCount
        {
            get { return maxFilterCount; }
            set { maxFilterCount = value; base.RaisePropertyChanged("MaxFilterCount"); }
        }

        private bool isTopChecked;
        public bool IsTopChecked
        {
            get { return isTopChecked; }
            set
            {
                isTopChecked = value; RaisePropertyChanged("IsTopChecked");
                FilterResultsOnCriteria();
            }
        }

        private ObservableCollection<string> allFilterConditions;
        public ObservableCollection<string> AllFilterConditions
        {
            get { return allFilterConditions; }
            set { allFilterConditions = value; base.RaisePropertyChanged("AllFilterConditions"); }
        }

        private Dictionary<string, string> filterConditions;
        public Dictionary<string, string> FilterConditions
        {
            get { return filterConditions; }
            set
            {
                filterConditions = value;

                ObservableCollection<string> allFilterConditions = new ObservableCollection<string>();
                foreach (string key in filterConditions.Keys) { allFilterConditions.Add(key); }
                AllFilterConditions = allFilterConditions;
            }
        }

        //public ICommand CountryFilterCommand { get; private set; } 
        #endregion

        public bool CanExecute(object parameter)
        {
            throw new NotImplementedException();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            throw new NotImplementedException();
        }
    }
}

// http://geekswithblogs.net/lbugnion/archive/2009/11/05/mvvm-light-toolkit-v3-alpha-2-eventtocommand-behavior.aspx
//      http://mvvmlight.codeplex.com/
// ?? - http://stackoverflow.com/questions/2094532/wpf-mvvm-icommand-binding-to-controls
// Navigation Overview - http://msdn.microsoft.com/en-us/library/ms750478(v=vs.100).aspx
// WPF: MVVM (Model View View-Model) Simplified - http://www.codeproject.com/Articles/36545/WPF-MVVM-Model-View-View-Model-Simplified
// http://www.danharman.net/2011/08/05/binding-wpf-events-to-mvvm-viewmodel-commands/

// http://stackoverflow.com/questions/10274637/how-to-handle-selectionchanged-event-in-via-delegate-command-when-the-combobox-i
// http://stackoverflow.com/questions/950501/how-do-you-handle-a-combobox-selectionchanged-in-mvvm




//AllFileDetails group fdet by fdet.NameSuggTemp into grp where grp.Count() > 1 select grp.Key).Count() > 0
//AllFileDetails.GroupBy(fdet => fdet.NameSuggested).Where(grp => grp.Count() > 0).Select(grp => new { Names = grp.Key, Count = grp.Count() })
        